//
//  ViewController.m
//  demo
//
//  Created by 马晓波 on 2019/12/20.
//  Copyright © 2019 马晓波. All rights reserved.
//

#import "ViewController.h"

@interface ViewController()
@property (nonatomic, strong) NSButton *btn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.wantsLayer = true;
    [self.view addSubview:self.btn];
    NSLog(@"111111");
    self.view.layer.backgroundColor = NSColor.redColor.CGColor;
    // Do any additional setup after loading the view.
}

+ (void)load
{
    NSLog(@"111111");
}

- (void)setRepresentedObject:(id)representedObject {
    [super setRepresentedObject:representedObject];

    // Update the view, if already loaded.
}

- (void)btnClick
{
    //定义alert变量
    NSAlert *alert = [[NSAlert alloc]init];
    //添加Ok按钮
    [alert addButtonWithTitle:@"Ok"];
    //弹窗内容
    alert.messageText = @"Hello World!";
    //描述性文字
    alert.informativeText = @"This is my first MAC app.";
    [alert beginSheetModalForWindow:[self.view window] completionHandler:^(NSModalResponse returnCode){
        if(returnCode == NSAlertFirstButtonReturn){
            NSLog(@"this is OK Button tap");
        }
    }];
}

- (NSButton *)btn
{
    if (!_btn) {
        _btn = [[NSButton alloc] initWithFrame:NSMakeRect(self.view.frame.size.width/2 - 30, self.view.frame.size.height/2 - 10, 60, 20)];
        [_btn setTitle:@"按钮"];
        [_btn setTarget:self];
        [_btn setAction:@selector(btnClick)];
        _btn.toolTip = @"提示的文字";
    }
    return _btn;
}
@end
